package com.xwb.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xwb.domain.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserDao extends BaseMapper<User> {

    @Select("select * from user where user_id = #{userId}")
    User selectStudentById(String userId);

    @Select("select * from user where user_name = #{userName}")
    User selectStudentByUserName(String userName);

    @Insert("INSERT INTO user (user_name, password,user_id) VALUES (#{user.userName}, #{user.password},#{user.userId})")
    void userRegister(@Param("user") User user);


    /**
     * 将加密后的密码存入数据库
     */
    @Update("UPDATE user\n" +
            "SET password = #{password}\n" +
            "WHERE user_name = #{userName};")
    void updateEncryptedPassword(@Param("userName") String userName, @Param("password") String password);

    /**
     * 设置用户的默认角色
     */
    @Insert("INSERT INTO `user_role` (`user_id`, `role_id`) VALUES (#{userId}, 1)")
    void setUserNormalRole(@Param("userId") String userId);

}
